package huajiu.com.dao;

import huajiu.com.base.BaseDao;
import huajiu.com.domain.ToningSolution;
import huajiu.com.vo.SolutionVo;

import java.util.List;

import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;


@Repository
@Transactional
public class ToningSolutionDao {
	
	@Autowired
	private BaseDao<ToningSolution> baseDao;
	
	
	public void save(ToningSolution toningSolution){
		baseDao.save(toningSolution);
	}
	
	public void delete(int id){
		ToningSolution toningSolution = (ToningSolution) baseDao.getCurrentSession().get(ToningSolution.class, id);
		baseDao.delete(toningSolution);
	}
	
	public void update(ToningSolution toningSolution){
		baseDao.save(toningSolution);
	}
	
	public List<SolutionVo> query(){
		String hqlString=" select t.* ,a.doctor from toning_solution t ,doctor_solution a where t.doctor_solution_uuid=a.uuid; ";
		List<SolutionVo> toningSolutions = baseDao.getCurrentSession().createSQLQuery(hqlString).list();
		return toningSolutions;
	}
	public ToningSolution querySolutionById(int id){
		return (ToningSolution) baseDao.getCurrentSession().get(ToningSolution.class, id);
	}
	
	public ToningSolution getToningSolution(String corporeity,String uuid){
		String hqlString = " select t.* from toning_solution t where t.corporeity = :corporeity and t.doctor_solution_uuid=:uuid";
		return (ToningSolution) baseDao.getCurrentSession().createSQLQuery(hqlString).addEntity(ToningSolution.class).setParameter("corporeity", corporeity).setParameter("uuid",uuid).list().get(0);
	}
	
	

}
